package com.study.common.utils;

import java.util.List;

import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import com.study.common.exception.BizException;

/**
 * request 请求验证工具类
 * RequestValidateUtil.java
 * @author yaojinshan
 * @since 2018年6月22日上午9:57:27
 */
public class RequestValidateUtil {
	/**
	 * 检查vo对象
	 */
	public static void checkVo(BindingResult validResult) throws BizException{
		String msg = "";
		if(validResult.hasErrors()){
    		List<ObjectError> allErrors = validResult.getAllErrors();
    		for (ObjectError error : allErrors) {
    			msg += error.getDefaultMessage() + ",";
			}
    		msg = msg.substring(0, msg.length() - 1);
    		throw new BizException(msg);
    	}
	} 
	/**
	 * 
	 */
	public static String getErrorMsgString(BindingResult validResult){
		String msg = "";
		if(validResult.hasErrors()){
			List<ObjectError> allErrors = validResult.getAllErrors();
			for (ObjectError error : allErrors) {
				msg += error.getDefaultMessage() + ",";
			}
		}
		return msg;
	} 
}
